# encoding: utf-8



import xadmin
from django.contrib.auth.models import Group, Permission



from xadmin.models import Log

# 和X admin的view绑定
from xadmin import views

from .models import Article
from message.models import Mseeage


# X admin的全局配置信息设置
class BaseSetting(object):
    # 主题功能开启
    enable_themes = True
    use_bootswatch = True

# x admin 全局配置参数信息设置
class GlobalSettings(object):
    site_title = "blog后台"
    site_footer = "sc珉 blog"
    # 收起菜单
    # menu_style = "accordion"

    def get_site_menu(self):
        return (
            {'title': '文章管理', 'menus': (
                {'title': '文章信息', 'url': self.get_model_url(Article, 'changelist')},

            )},
            {'title': '留言管理', 'menus': (
                {'title': '留言信息', 'url': self.get_model_url(Mseeage, 'changelist')},

            )},


        )


# 创建admin的管理类,这里不再是继承admin，而是继承object
class ArticleAdmin(object):
    # 配置后台我们需要显示的列
    list_display = ['title', 'article_desc','article_type', 'add_time']
    # 配置搜索字段,不做时间搜索
    search_fields = ['title', 'article_desc','article_type', 'add_time']
    # 配置筛选字段
    list_filter = ['title', 'article_desc','article_type', 'add_time']




# 将model与admin管理器进行关联注册
xadmin.site.register(Article, ArticleAdmin)


# 将Xadmin全局管理器与我们的view绑定注册。
xadmin.site.register(views.BaseAdminView, BaseSetting)

# 将头部与脚部信息进行注册:
xadmin.site.register(views.CommAdminView, GlobalSettings)